const app = getApp();
Page({
    data:{
        listArr:[],
        listid: 0,
        runner:{}
   
    },
    /**
     * 页面的初始数据
     */
    chaxun(){
      var that=this;
      wx.request({  
        url: 'https://www.woodymidnight.cn/BCUHelper/api/list/selectbylistid',  
        method: 'POST',
        data:{
          listId : this.data.listid
        },                                      
        header: { 'content-type': 'application/x-www-form-urlencoded' }, 
        success: res => {   
          var resData = res.data;
          var data = res.data.data;
          console.log("购物车数据" , data);
          console.log("数据" , resData);
          console.log("this:",this);
          data.listtime = that.toData(data.listtime)
          that.setData({
            listArr: resData.data
          })

          if(this.data.listArr.liststate != 1){
            wx.request({  
              url: 'https://www.woodymidnight.cn/BCUHelper/api/user/selectuserbyid',  
              method: 'POST',
              data:{
                userId : this.data.listArr.runnerid
              },                                      
              header: { 'content-type': 'application/x-www-form-urlencoded' }, 
              success: res => {   
                console.log(res);
                this.setData({
                  runner: res.data.data
                })
              }
            })
          }

        }
      })
    },

    makecall: function(t) {
      wx.makePhoneCall({
          phoneNumber: this.data.listArr.runnerphone
      });
    },
    
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
      console.log(options);
      var listid = parseInt(options.listid);
      this.setData({
          listid : listid
      })
      this.chaxun();
  },
  toData : function(number){
    var n=number;
    var date = new Date(n);
    var Y = date.getFullYear() + '/';
    var M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '/';
    var D = date.getDate()<10 ? '0'+date.getDate() : date.getDate();
    return (Y+M+D)
  },

  finish:function(res){
    wx.request({  
      url: 'https://www.woodymidnight.cn/BCUHelper/api/list/finishlist',  
      method: 'POST',
      data:{
        listId : this.data.listArr.listid
      },                                      
      header: { 'content-type': 'application/x-www-form-urlencoded' }, 
      success: res => {   
        console.log(res);
        wx.navigateBack({
          delta: 1,
        })
      }
    })
  },

  cancel:function(res){
    wx.request({  
      url: 'https://www.woodymidnight.cn/BCUHelper/api/list/delete',  
      method: 'POST',
      data:{
        ListId : this.data.listArr.listid
      },                                      
      header: { 'content-type': 'application/x-www-form-urlencoded' }, 
      success: res => {   
        console.log(res);
        wx.navigateBack({
          delta: 1,
        })
      }
    })
  },
   
  toData : function(number){
    var n=number;
    var date = new Date(n);
    var Y = date.getFullYear() + '/';
    var M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '/';
    var D = date.getDate()<10 ? '0'+date.getDate() : date.getDate();
    return (Y+M+D)
  }
    
})
